<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../../css/aui_font.css" />
    <link rel="stylesheet" type="text/css" href="../../css/news.css" />
    <link rel="stylesheet" type="text/css" href="../../css/frame3.css" />
    <style>
        html,
        body {
            background-color: #fff;
        }
        .container{
            padding: 20px 10px;
        }
       .left-gray{
           width: 11px;
           padding-left: 7px;
           display: block;
       }
       .lay{
           display: flex;
           justify-content: flex-start;
           padding: 20px 0 10px 8px;
       }
       .shipin{
           width: 81px;
           height: 89px;
           margin-left: 10px;
       }
       #textarea{
           flex: 1;
       }
       .title{
           /* background-color: #f8f4fe; */
           border-radius: 5px;
           margin-top: 10px;
           padding: 10px;
           display: flex;
           justify-content: flex-start;
           align-items: center;
           margin-top: 4px;
       }
       .title span{
           color: #6F6D6D;
           font-size: 13px;
       }
       .coins{
           width: 28px;
           margin-right: 6px;
       }
       .set{
           border-bottom: 1px solid #dadada;
           padding-bottom: 15px;
       }
       .feiyong{
           padding: 4px 0 0 34px;
           display: flex;
           justify-content: flex-start;
           align-items: center;
           flex-wrap: wrap;
       }
       .feiy{
           width: 200px;
           padding: 0 12px;
           background-color: #ececec;
           border-radius: 100px;
           display: flex;
           justify-content: flex-start;
           align-items: center;
           margin: 0 5px 5px 0;
       }
       .msg{
           width: 100%;
           color: #000000;
           font-size: 10px;
           text-align: center;
           margin-left: 7px;
       }
       .btn-box{
        width: 70%;
           display: block;
           margin: 100px auto 20px auto;
           position: relative;
       }
       .btn{
           width: 100%;
           font-size: 17px;
           color: #ffffff;
           border-radius: 100px;
           padding: 10px 0;
             background-image: linear-gradient(to right, #da69c0 ,#753ece);
           
       }
       .edit{
           position: absolute;
           left: 28%;
           bottom: 18px;
       }
       .tip{
           background-color: #f8f4fe;
           border-radius: 5px;
           margin-top: 10px;
           padding: 10px;
       }
       .wenzi{
           color: #999;
           font-size: 12px;
       }
    </style>
</head>

<body>
    <div id="view" class="container">
        <div class="lay">
            <textarea name="wenben" v-model="desc" id="textarea" cols="30" rows="5" placeholder="添加视频描述..."></textarea>
            <img :src="returnImg(cover_url) || '../../image/icon/camera.png'" onclick="upVideo()" class="shipin"/>
       
        </div>
        <div class="set">
            <div class="title">
                <img src="../../image/zhibo/coins.png" class="coins"/> 
                <span>设置费用</span>
            </div>
            <div class="feiyong">
                <span class="feiy">
                    <img src="../../image/zhibo/$.png" />
                    <input class="msg" type="number" min="0" v-model="fee" placeholder="x金币可观看一个视频">
                    <!-- <span class="msg"></span> -->
                </span>
            </div>
       
        </div>
        <div>
            <div class="title">
                <img src="../../image/zhibo/xuzhi.png" class="coins"/> 
                <span>发布须知</span>
            </div>
            <div class="wenzi" >
                <p  v-html="video_desc"></p>
            </div>
        </div>
        <div class="btn-box">
            <button class="btn" onclick="sub()">发布</button>
            <img src="../../image/zhibo/edit.png" class="edit">
        </div>
       
           
    </div>
    <script type="text/javascript" src="../../script/api.js"></script>
    <script type="text/javascript" src="../../script/jquery.js"></script>
    <script type="text/javascript" src="../../script/ffkj.js"></script>
    <script type="text/javascript" src="../../script/vue.js"></script>
    <script type="text/javascript" src="../../script/update.js"></script>
    <script type="text/javascript">
        var view = new Vue({
            el: '#view',
            data: {
                id: null,
                user_id: null,
                cover_url: '',
                video_url: '',
                desc: '',
                video_desc : '',
                fee: 0,
                ffInfo: {},
                ios: 1, // 1上架 0非上架
                version: '0.0.1'
            },
            methods: {
                _url(param, url) {
                    _url(param, url);
                },
                // 返回图片路径
                returnImg(url) {
                    if(url.indexOf('/disk') == 0){
                        return returnImg(url);
                    }else{
                        return url;
                    }


                },

              }
        })
        apiready = function() {
            view.user_id = $api.getStorage('userid');
            if(api.pageParam['info']){
                console.log('info',JSON.stringify(api.pageParam['info']))
                let {id, cover_url, video_url, desc, fee} = api.pageParam['info']
                view.cover_url = cover_url || ''
                view.video_url = video_url || ''
                view.desc = desc || ''
                view.fee = fee || 0
                view.id = id || null
            }
            getInfo();
        }

        function  upVideo(){
            let app = view
            var buttons = [ '拍摄', '相册'];
            _action('', buttons, function(bIndex) {
                openPicUrl(function(result) {
                    getVideoCover(result.data, function(cover) {
                        app.video_url = result.data;
                        app.cover_url = cover;
                    })
                }, bIndex, 'video')
            })

        }
        function sub(){
            // 发布视频
            let app = view;
            _loading();
            if (app.video_url.indexOf('/disk') == 0) {
                if(app.id){
                    _ajax('api/video/editVideo', function(ret, err) {
                        _loadingClose();
                        _msg(ret.msg);
                        if (ret && ret.code == 200) {
                            _send('upmevideo')
                            timerWin();
                        }
                    }, {
                        id: app.id,
                        user_id: app.user_id,
                        video_url: app.video_url,
                        cover_url: app.cover_url,
                        desc: app.desc,
                        fee: app.fee,
                        is_free: app.fee == 0 ? 1 : 2
                    })
                }else{
                    _ajax('api/video/addVideo', function(ret, err) {
                        _loadingClose();
                        _msg(ret.msg);
                        if (ret && ret.code == 200) {
                            _send('upmevideo')
                            timerWin();
                        }
                    }, {
                        user_id: app.user_id,
                        video_url: v,
                        cover_url: u,
                        desc: app.desc,
                        fee: app.fee,
                        is_free: app.fee == 0 ? 1 : 2
                    })
                }



            }else{
                if(app.id){
                    pushVideo(app.video_url, function(v) {
                        _upImg({
                            image: app.cover_url
                        }, function(u) {
                            _ajax('api/video/editVideo', function(ret, err) {
                                console.log(JSON.stringify(ret))
                                console.log(JSON.stringify(err))
                                _loadingClose();
                                _msg(ret.msg);
                                if (ret && ret.code == 200) {
                                    _send('upmevideo')
                                    timerWin();
                                }
                            }, {
                                id: app.id,
                                user_id: app.user_id,
                                video_url: v,
                                cover_url: u,
                                desc: app.desc,
                                fee: app.fee,
                                is_free: app.fee == 0 ? 1 : 2
                            })
                        })
                    })
                }else{
                    pushVideo(app.video_url, function(v) {
                        _upImg({
                            image: app.cover_url
                        }, function(u) {
                            _ajax('api/video/addVideo', function(ret, err) {
                                console.log(JSON.stringify(ret))
                                console.log(JSON.stringify(err))
                                _loadingClose();
                                _msg(ret.msg);
                                if (ret && ret.code == 200) {
                                    _send('upmevideo')
                                    timerWin();
                                }
                            }, {
                                user_id: app.user_id,
                                video_url: v,
                                cover_url: u,
                                desc: app.desc,
                                fee: app.fee,
                                is_free: app.fee == 0 ? 1 : 2
                            })
                        })
                    })
                }

            }


            //上传视频
        }
        function getInfo() {
            let app = view
            _ajax('api/member/config', function(ret, err) {
                if (ret && ret.code == 200) {
                
                    app.video_desc = ret.data['video_desc']
                }
            })
        }
    </script>
</body>

</html>